package com.cvtc29.www;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class Main extends Activity {
	private Button mBtnLoginDlg;
	private TextView mTxtResult;
	private Dialog mLoginDlg;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        setupViewComponent();
    }
    
    private void setupViewComponent() {
		mBtnLoginDlg = (Button)findViewById(R.id.BU001);
		mTxtResult = (TextView)findViewById(R.id.TV005);

		mBtnLoginDlg.setOnClickListener(btnLoginDlgOnClkLis);
    }

    private Button.OnClickListener btnLoginDlgOnClkLis = new Button.OnClickListener() {
		public void onClick(View v) {
			mTxtResult.setText("");
			
			mLoginDlg = new Dialog(Main.this);
			mLoginDlg.setTitle(getString(R.string.TV002));
			mLoginDlg.setCancelable(false);
			mLoginDlg.setContentView(R.layout.dlglogin);
			Button loginBtnOK = (Button)mLoginDlg.findViewById(R.id.BU002);
			Button loginBtnCancel = (Button)mLoginDlg.findViewById(R.id.BU003);
			loginBtnOK.setOnClickListener(loginDlgBtnOKOnClkLis);
			loginBtnCancel.setOnClickListener(loginDlgBtnCancelOnClkLis);
			mLoginDlg.show();			
		}
	};
	
    private Button.OnClickListener loginDlgBtnOKOnClkLis = new Button.OnClickListener() {
		public void onClick(View v) {
			EditText edtUserName = (EditText)mLoginDlg.findViewById(R.id.ED001);
			EditText edtPassword = (EditText)mLoginDlg.findViewById(R.id.ED002);

			mTxtResult.setText(getString(R.string.TV005) + getString(R.string.TV002) +edtUserName.getText().toString() +
					getString(R.string.TV003) + edtPassword.getText().toString());
			mLoginDlg.cancel();
		}
	};
	
    private Button.OnClickListener loginDlgBtnCancelOnClkLis = new Button.OnClickListener() {
		public void onClick(View v) {
			mTxtResult.setText(getString(R.string.TV006)+getString(R.string.BU003)+getString(R.string.TV007));
			mLoginDlg.cancel();
		}
	};

}

